<?php


namespace app\admin\logic;


use app\common\config\cache\CacheKey;
use app\common\config\Client;
use app\common\utils\Auth;

/**
 * Class Role
 * @package app\admin\logic
 * @property \app\common\model\Role modelRole
 */

class Role extends LogicBase
{
    /**
     *  获取角色列表
     */
    public function getList($data){
        $where = [];
        $where[] = ['client','=',getConfigModuleValue()];
        !empty($data['searchContent']) && $where[] = ['name','like','%'.$data['searchContent'].'%'];
        return $this->modelRole->where($where)->paginate(10);
    }

    /**
     * 新增角色信息
     */
    public function add($data){
        $data['client'] = getConfigModuleValue();
        $this->modelRole->add($data,\app\admin\middleware\Auth::$user->id);
    }

    /**
     * 编辑角色信息
     */
    public function update($data){
        return $this->modelRole->edit($data,\app\admin\middleware\Auth::$user->id);
    }

    /**
     * 删除角色信息
     */
    public function del($data){
        $this->modelRole->del($data,\app\admin\middleware\Auth::$user->id);
    }

    /**
     *  获取角色列表
     */
    public function getOption($data){
        $where = [];
        $where[] = ['client','=',getConfigModuleValue()];
        !empty($data['searchContent']) && $where[] = ['name','like','%'.$data['searchContent'].'%'];
        return $this->modelRole->field(['id','name'])->where($where)->select();
    }
}